package com.jamila.scancode.exception;

import com.jamila.scancode.result.ResultCodeEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Description: 自定义异常信息类
 * @CreateTime: 2024-03-30  22:04
 * @Author: JAMILA
 * @Version: 1.0
 */

@Data
//@AllArgsConstructor//有参构造器
@NoArgsConstructor//无参构造器
public class JamilaException  extends  RuntimeException  {
    private Integer code;

    private String message;

    /**
     * 通过状态码和错误消息创建异常对象
     * @param code
     * @param message
     */
    public JamilaException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    /**
     * 接收枚举类型对象
     * @param resultCodeEnum
     */
    public JamilaException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
        this.message = resultCodeEnum.getMessage();
    }

    @Override
    public String toString() {
        return "JamilaException{" +
                "code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }
}
